import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from "@angular/router";
import {Observable} from "rxjs/Observable";
import {Injectable} from "@angular/core";
import {ProductComponent} from "../product/product.component";

@Injectable()
export class ProductResolve implements Resolve<ProductComponent>{

  constructor(private router: Router) {

  }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<ProductComponent>|Promise<ProductComponent>|ProductComponent{
    let productId:number = route.params["id"];

    if(productId == 1) {
      return new Product(1, "iphone7");
    }else {
      this.router.navigate(['/home']);
      return undefined;
    }

  }
}
